//
//  HTSearchListView.swift
//  MagaCore
//
//  Created by MrMessy on 2023/5/7.
//

import SwiftUI

struct HTSearchListView: View {

  @Binding var var_suggestions: [String]
  @State var var_onClick: ((String) -> Void)?

  var body: some View {
    ScrollView(showsIndicators: false){
      VStack(spacing: 0){
        ForEach(var_suggestions, id:\.self) { suggestion in
          VStack(alignment: .leading, spacing: 0){
            Text(suggestion)
              .font(.system(size: 13))
              .ht_normal()
              .padding(.vertical, 15)
            Divider()
          }
          .frame(maxWidth: .infinity)
          .padding(.leading, 15)
          .background(Color(hex: "#f5f5f5"))
          .onTapGesture {
            UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
            if (var_onClick != nil) {
              var_onClick!(suggestion)
            }
          }
        }
      }
      .frame(maxWidth: .infinity, maxHeight: .infinity)
    }
    .background(Color(hex: "#f5f5f5"))
    .frame(maxWidth: .infinity, maxHeight: .infinity)
    .onAppear{
      HTNetworkManager().ht_requestForBuried(.htEnumSearchShNew)
    }
  }
}
